package generator.controller;

import com.atkt.ktkt.model.vod.Chapter;
import com.atkt.ktkt.vo.vod.ChapterVo;
import generator.service.ChapterService;
import ktkt.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author KT917
 * @date 2022/9/18
 */

@RestController
@RequestMapping(value="/admin/vod/chapter")
//@CrossOrigin
@Api(tags = "课程章节")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    //1.大纲列表
    @ApiOperation("大纲列表")
    @GetMapping("getNestedTreeList/{courseId}")
    public Result getTreeList(@PathVariable Long courseId){
        List<ChapterVo> chapterVos=chapterService.getTreeList(courseId);
        return Result.ok(chapterVos);
    }
    //2. 添加章节
    @PostMapping("/save")
    public Result save(@RequestBody Chapter chapter){
        chapterService.save(chapter);
        return  Result.ok(null);
    }

    //3. 修改-根据id查询
    @GetMapping("/get/{id}")
    public Result get(@PathVariable Long id){
        Chapter byId = chapterService.getById(id);
        return  Result.ok(null);
    }

    //4. 修改最终实现
    @PostMapping("/update")
    public Result update(@RequestBody Chapter chapter){
        chapterService.updateById(chapter);
        return  Result.ok(null);
    }

    //5. 删除章节
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable Long id){
        chapterService.removeById(id);
        return Result.ok(null);
    }


}
